import Vue from 'vue'
import axios from 'axios';
let wx = require('weixin-js-sdk');
const jsApiList = ['onMenuShareAppMessage', 'onMenuShareTimeline'];

export default {
    // 获取JSSDK
    getJSSDK(url) {
        axios.post('http://api.ittie.cn/api/wechat/jssdk', {url: url}).then((response) => {
            let res = response.data;
            let self = this;
            const wxconfig = {
                debug: res.debug,
                appId: res.appId,
                timestamp: res.timestamp,
                nonceStr: res.nonceStr,
                signature: res.signature,
                jsApiList: res.jsApiList
            };
            wx.config(wxconfig)
        })
    },
    setWxShare(title, desc, link, imgUrl) {
        wx.ready(() => {
            // 分享给朋友
            wx.onMenuShareAppMessage({
                title: title, // 分享标题
                desc: desc,   // 分享描述
                link: link,   // 分享链接 默认以当前链接
                imgUrl: imgUrl, // 分享图标
                success() {
                },
                cancel() {
                }
            })
            // 分享到朋友圈
            wx.onMenuShareTimeline({
                title: title, // 分享标题
                desc: desc,   // 分享描述
                link: link,   // 分享链接 默认以当前链接
                imgUrl: imgUrl, // 分享图标
                success() {
                },
                cancel() {
                }
            })
        })
    }
}
